<%@ taglib uri="/tags/struts-bean" prefix="bean"%>
<%@ taglib uri="/tags/struts-html" prefix="html"%>
<%@ taglib uri="/tags/struts-logic" prefix="logic"%>
<%@ taglib uri="/tags/core" prefix="c"%>
<%@ taglib uri="/tags/fmt" prefix="fmt"%>
<script type="text/javascript" src="js/utils.js"></script>
<script type="text/javascript">

	function validate(){
			var someChecked = false;   
			if(document.InstructionPurchaseDetailSearchForm.checkboxId.length != undefined){
				for (var i=0; i < document.InstructionPurchaseDetailSearchForm.checkboxId.length; i++) {
				   if (document.InstructionPurchaseDetailSearchForm.checkboxId[i].checked){
				      someChecked = true;
				      break;
				   }
				 }	
			}else{				
				if(document.InstructionPurchaseDetailSearchForm.checkboxId.checked){
					someChecked = true;
				}	
			}
			return someChecked;
		}
		function submitForm(action){
			if(validate()){
		    	var form = document.getElementById('mainForm');	    	
		    	form.action = action;
		    	form.submit();	
	    	}else{
	    		alert('<bean:message key="error.purchases.instructions.select.product"/>');
	    	}    	   
		}
</script>

<html:form action="/ipdSearchProductResult.do" styleId="mainForm">
<br />
<table id="tabla" align="center" width="400" cellpadding="2" cellspacing="1" border="0" bgcolor="#CCCCC0">
  <tr>
	<td colspan="3" class="titulocolumna" align="center"> <bean:message key="label.common.results"/> </td>
  </tr>  
  <tr>
  	<td class="etiqueta" align="center" width="30">&nbsp;&nbsp;</td>  	
  	<td class="columnadatoNon" align="center" width="90"> <bean:message key="message.futurepurchase.customer.code"/> </td>
  	<td class="columnadatoNon" align="center" width="280"> <bean:message key="message.futurepurchase.customer.name"/> </td>  	
  </tr>
  <logic:notEmpty name="listOfProducts">
		<logic:iterate id="row" name="listOfProducts" indexId="int_i">
			<tr class="<%=((int_i.intValue()%2)==0?"columnadatoPar":"columnadatoNon")%>">																			
				<td align="center">					 										
					<bean:define id="numberValue"><bean:write name="row" property="productId"/></bean:define> 											
					<html:multibox styleId="checkboxId" property="selectedProducts" value="<%=numberValue%>" /> 			
				</td>										
				<td align="center"><bean:write name="row" property="productId"/></td>
				<td align="left"><bean:write name="row" property="description"/></td>					
			</tr>
		</logic:iterate>
	</logic:notEmpty>
	<tr>
	<td colspan="3" align="left" class="columnadatoPar">		
		<logic:notEmpty name="listOfProducts">
			<html:button property="submitAction" onclick="javascript:submitForm('ipdSelectProduct.do')" styleClass="boton_large"><bean:message key="label.common.save"/></html:button>&nbsp;&nbsp;				
		</logic:notEmpty>
		<logic:empty name="listOfProducts">
			<html:button disabled="true" property="submitAction" onclick="javascript:submitForm('ipdSelectProduct.do')" styleClass="boton_large"><bean:message key="label.common.save"/></html:button>&nbsp;&nbsp;				
		</logic:empty>
		
		<html:button styleClass="boton" property="backButton" onclick="location.href='resumeInstructionPurchaseDetail.do';"> <bean:message key="label.common.back"/> </html:button>											
	</td>
	</tr>
</table>
</html:form>
<br />
<br />